using System.Collections.Generic;
using OhioState.Graphics;
using OhioState.Graphics.Proxy;
using OhioState.Math;
using Tao.OpenGl;

namespace OhioState.Graphics.OpenGL
{

    public class AxesPlaneGL : IDrawable
    {
        List<Vector3> _vertices1, _vertices2, _vertices3;
        //Vector3 _normal;
        public AxesPlaneGL(List<Vector3> vertices1,List<Vector3> vertices2,List<Vector3> vertices3)
        {
            _vertices1 = vertices1;
            _vertices2 = vertices2;
            _vertices3 = vertices3;
          //  _normal = normal;
        }

        #region GL Methods
        //
        // Render the ROI
        //
        public void Render(IRenderPanel panel)
        {
            Gl.glColor4f(_color.R, _color.G, _color.B, _color.A);
            _material.MakeActive(panel);
            RenderSlice();
            _material.Deactivate(panel);
        }
        
        public void FindIntersections(AxesPlaneProxy slp)
        {
            slp.FindIntersections();
            _vertices1 = slp.XYSlice;
            _vertices2 = slp.XZSlice;
            _vertices3 = slp.YZSlice;

        }
        private void RenderSlice()
        {
            Gl.glDisable(Gl.GL_CULL_FACE);
            Gl.glNormal3f(0, 0, 1);
            Gl.glBegin(Gl.GL_TRIANGLE_FAN);
            //List<Vector3> slice = _slicer.CurrentSlice;
           
            foreach( Vector3 vert in _vertices1)
            {
                //
                // Set the texture coordinates?
                //
                try
                {
                    Gl.glTexCoord3fv(vert.getValue());
                    Gl.glVertex3fv(vert.getValue());
                }
                catch { }
            }
            Gl.glEnd();


            Gl.glNormal3f(0, 1, 0);
            Gl.glBegin(Gl.GL_TRIANGLE_FAN);
            foreach (Vector3 vert in _vertices2)
            {
                try
                {
                    Gl.glTexCoord3fv(vert.getValue());
                    Gl.glVertex3fv(vert.getValue());
                }
                catch { }
            }
            Gl.glEnd();

            Gl.glNormal3f(1, 0, 0);
            Gl.glBegin(Gl.GL_TRIANGLE_FAN);
            foreach (Vector3 vert in _vertices3)
            {
                try
                {
                    Gl.glTexCoord3fv(vert.getValue());
                    Gl.glVertex3fv(vert.getValue());
                    
                }
                catch { }
            }
            Gl.glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
            Gl.glEnd();

        }
        public void Update(IRenderPanel panel)
        {
        }
        #endregion

        #region Public Properties
        private IMaterial _material;
        public IMaterial Material
        {
            get { return _material; }
            set { _material = value; }
        }

        private OSUColor _color;
        public OSUColor Color
        {
            get { return _color; }
            set { _color = value; }
        }
        public IBoundingVolume BoundingVolume
        {
            get { return null; }
        }
        private int _drawablePosition;
        public int DrawablePosition
        {
            get { return _drawablePosition; }
            set { _drawablePosition = value; }
        }

        #endregion Public Properties

    }
}
